//
//  SHGMainViewController.swift
//  -微博准备
//
//  Created by 孙护国 on 16/4/7.
//  Copyright © 2016年 孙护国. All rights reserved.
//

import UIKit

class SHGMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
let mainTabBar=SHGTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        addChildViewControllers()
    }


    func addChildViewControllers() {
        addChildViewController(SHGHomeViewController(), title: "首页", imageName: "tabbar_home")
          addChildViewController(SHGMessageViewController(), title: "消息", imageName: "tabbar_message_center")
          addChildViewController(SHGDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
          addChildViewController(SHGHomeViewController(), title: "我", imageName: "tabbar_profile")
    }
    func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        //同时设置tabbaritem的题目和导航控制器的题目
        vc.title=title
        //设置图片
        vc.tabBarItem.image=UIImage(named: imageName)
        //设置被选中的图片
        vc.tabBarItem.selectedImage=UIImage(named: imageName+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        let nvc=UINavigationController(rootViewController: vc)
        addChildViewController(nvc)
    }
  }
